<template>
	<view class="myCommentListPage">
		<view class="listContent">
			<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"
				v-if="!list.length && !isLoading && isLoad" text="没有更多了"></u-empty>
			<view v-for="(item,index) in list" :key="index" @click="goDetail(item.id)" class="list">
				<view class="itemTop">
					<view class="topRight">
						<u--image :src="item.images?(baseUrl+'/sys/common/static/'+item.images.split(',')[0]):''"
							shape="square" mode="aspectFill" width="208rpx" height="150rpx" bgColor="transparent"
							radius="8rpx"></u--image>
					</view>
					<view class="topLeft">
						<view class="title">{{item.name}}</view>
						<view class="talk">
							<view>{{item.createTime}}</view>
						</view>
					</view>
				</view>
				<view class="itemBottom">
					<view class="operate">
						<view class="item">
							<u--image src="/static/community/4.png" shape="square" mode="aspectFill" width="30rpx"
								height="24rpx"></u--image>
							<view class="count">{{item.readingVolume||0}}</view>
						</view>
						<view class="item">
							<u--image src="/static/community/5.png" shape="square" mode="aspectFill" width="26rpx"
								height="26rpx"></u--image>
							<view class="count">{{item.replyCount||0}}</view>
						</view>
					</view>
				</view>
				<view class="commentInfo">
					<view class="date">{{item.commentTime}}</view>
					<view class="info">{{item.text}}</view>
				</view>
			</view>
			<u-loadmore v-if="list.length" :status="isFinish?'nomore':'loading'" loading-text="正在加载"
				loadmore-text="加载更多" nomore-text="没有更多了" color="#d0d0d0" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: this.$api.baseUrl,
				list: [],
				pageNo: 1,
				pageSize: 10,
				total: 0,
				isFinish: false,
				isLoading: false,
				isLoad: false,
				userId: ""
			}
		},
		onReachBottom() {
			if (!this.isLoading && !this.isFinish) {
				this.pageNo++;
				this.initData();
			}
		},
		onPullDownRefresh() {
			this.isFinish = false;
			if (!this.isLoading) {
				this.pageNo = 1;
				this.list = [];
				this.initData(true);
			}
		},
		onLoad() {
			uni.getStorage({
				key: "userInfo",
				success: (userInfo) => {
					this.userId = userInfo.data.id;
					this.initData();
				}
			})
		},
		methods: {
			initData(isRefresh) {
				this.isLoading = true;
				Promise.all([
					this.$request.get(this.$api.commentList, {
						userId: this.userId,
						pageNo: this.pageNo,
						pageSize: this.pageSize
					}),
				]).then(res => {
					uni.hideLoading()
					if (isRefresh) {
						uni.stopPullDownRefresh()
					}
					this.isLoading = false;
					this.list = this.list.concat(res[0].result.records)
					this.total = res[0].result.total;
					if (this.pageNo * this.pageSize < this.total) {
						this.isFinish = false
					} else {
						this.isFinish = true
					}
					this.isLoad = true;
				})
			},
			goDetail(id) {
				uni.navigateTo({
					url: "/pages/postDetail/postDetail?id=" + id
				})
			},
		}
	}
</script>

<style lang="scss">
	.myCommentListPage {
		.listContent {
			display: flex;
			flex-direction: column;
			padding: 20rpx 40rpx;

			.list {
				display: flex;
				flex-direction: column;
				padding: 30rpx 20rpx 24rpx;
				background: #FFFFFF;
				box-shadow: inset 0px 0px 0px 1rpx rgba(230, 230, 230, .5);
				border-radius: 10px 10px 10px 10px;
				margin-bottom: 20rpx;

				.itemTop {
					display: flex;
					flex-wrap: nowrap;
					justify-content: flex-start;
					padding-bottom: 20rpx;

					.topLeft {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						width: 100%;
						padding-left: 20rpx;

						.title {
							font-family: PingFang SC-Bold, PingFang SC;
							font-weight: bold;
							color: #333333;
							font-size: 28rpx;
							letter-spacing: 1rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-line-clamp: 3;
							-webkit-box-orient: vertical;
							padding-right: 20rpx;
						}

						.talk {
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
							font-size: 26rpx;
							display: flex;
							flex-wrap: nowrap;
							overflow: auto;
							margin-right: 20rpx;

							.talkItem {
								flex-shrink: 0;
							}
						}
					}

					.topRight {
						flex-shrink: 0;
					}
				}

				.itemBottom {
					display: flex;
					flex-wrap: nowrap;
					justify-content: space-between;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					font-size: 26rpx;
					padding-bottom: 20rpx;
					border-bottom: 1rpx solid #EEEEEE;

					.operate {
						display: flex;
						flex-wrap: nowrap;

						.item {
							display: flex;
							flex-wrap: nowrap;
							align-items: center;
							padding-right: 40rpx;

							.count {
								padding-left: 10rpx;
							}
						}
					}
				}

				.commentInfo {
					padding: 20rpx;

					.date {
						font-size: 26rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
						padding: 10rpx 0;
					}

					.info {
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
					}
				}
			}
		}
	}
</style>
